<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/17
 * Time: 1:30
 */

namespace App\HttpController\V1;


use App\Common\Checking;

class Menu extends BaseWithDb
{
    /**
     * 一级菜单
     */
    public function top_menu(){
        $top=$this->db->where('pid',1)->get('study_class',null,'id,class_name');
        return $this->writeJson(200,$top);
    }

    /**
     * 子分类
     * input:class_id 分类ID
     */
    public function two_menu(){
        $class=$this->db->where('pid',1)->getColumn('study_class','id');
        $input=$this->input();
        if (!Checking::keyIsExistence('class_id',$input)){
            return $this->writeJson(201,Checking::MESSAGE['keyIsExistence']);
        }
        if (!in_array($input['class_id'],$class)){
            return $this->writeJson(201,null,'参数异常');
        }
        $two=$this->db->where('pid',$input['class_id'])->get('study_class',null,'id,class_name');
        return $this->writeJson(200,$two);
    }

    /**
     * 所有栏目 TODO 未写
     */
    public function all_menu(){
        $top=$this->db->where('pid',1)->get('study_class',null,'id,class_name');
    }
}